<html>
<head><meta charset="utf-8"><title>local crate only queries? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/local.20crate.20only.20queries.3F.html">local crate only queries?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="238170720"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/local%20crate%20only%20queries%3F/near/238170720" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cameron Steffen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/local.20crate.20only.20queries.3F.html#238170720">(May 10 2021 at 16:23)</a>:</h4>
<p>Why are there so many queries that accept a <code>CrateNum</code> and then <code>assert_eq!(cnum, LOCAL_CRATE)</code>?</p>



<a name="238170864"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/local%20crate%20only%20queries%3F/near/238170864" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/local.20crate.20only.20queries.3F.html#238170864">(May 10 2021 at 16:24)</a>:</h4>
<p>queries for external crates are provided separately, usually by <code>rustc_metadata</code></p>



<a name="238174069"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/local%20crate%20only%20queries%3F/near/238174069" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cameron Steffen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/local.20crate.20only.20queries.3F.html#238174069">(May 10 2021 at 16:45)</a>:</h4>
<p>Thank you! That makes sense.</p>



<a name="238174490"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/local%20crate%20only%20queries%3F/near/238174490" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cameron Steffen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/local.20crate.20only.20queries.3F.html#238174490">(May 10 2021 at 16:48)</a>:</h4>
<p>So where is ..? <code>if cnum != LOCAL_CRATE { /* use rust_metadata */ }</code></p>



<a name="238174565"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/local%20crate%20only%20queries%3F/near/238174565" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/local.20crate.20only.20queries.3F.html#238174565">(May 10 2021 at 16:49)</a>:</h4>
<p>rustc_query_system, I think, and it's based on either looking in the extern_providers or local_providers (I may be getting names slightly wrong)</p>



<a name="238174919"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/local%20crate%20only%20queries%3F/near/238174919" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/local.20crate.20only.20queries.3F.html#238174919">(May 10 2021 at 16:51)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/blob/544d124b81fb54e1904b6cd53de9bf92b6b3d0b9/compiler/rustc_query_impl/src/plumbing.rs#L393-L398">https://github.com/rust-lang/rust/blob/544d124b81fb54e1904b6cd53de9bf92b6b3d0b9/compiler/rustc_query_impl/src/plumbing.rs#L393-L398</a></p>



<a name="238175402"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/local%20crate%20only%20queries%3F/near/238175402" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cameron Steffen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/local.20crate.20only.20queries.3F.html#238175402">(May 10 2021 at 16:54)</a>:</h4>
<p><code>cache.cache.lookup(cache, ..</code><br>
It's all clear now <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<a name="238175538"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/local%20crate%20only%20queries%3F/near/238175538" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cameron Steffen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/local.20crate.20only.20queries.3F.html#238175538">(May 10 2021 at 16:55)</a>:</h4>
<p>good pointer though. I'll do more digging.</p>



<a name="238305448"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/local%20crate%20only%20queries%3F/near/238305448" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cameron Steffen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/local.20crate.20only.20queries.3F.html#238305448">(May 11 2021 at 13:20)</a>:</h4>
<p><span class="user-mention" data-user-id="248906">@cjgillot</span> Is <a href="https://github.com/rust-lang/rust/issues/85178">#85178</a> inspired by this thread? You said</p>
<blockquote>
<p>The pervasive CrateNum parameter is a remnant of the multi-crate rustc idea.</p>
</blockquote>
<p>Does that mean the queries could be/will be strictly local crate?</p>
<p>Also, I wonder if we could have <code>tcx.local().query()</code> instead of <code>tcx.query(())</code></p>



<a name="238305793"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/local%20crate%20only%20queries%3F/near/238305793" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/local.20crate.20only.20queries.3F.html#238305793">(May 11 2021 at 13:22)</a>:</h4>
<p>TBH, I did not give enough attention to this thread.</p>



<a name="238305936"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/local%20crate%20only%20queries%3F/near/238305936" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/local.20crate.20only.20queries.3F.html#238305936">(May 11 2021 at 13:23)</a>:</h4>
<p>The queries that take <code>()</code> will are strictly crate local.</p>



<a name="238306375"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/local%20crate%20only%20queries%3F/near/238306375" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/local.20crate.20only.20queries.3F.html#238306375">(May 11 2021 at 13:26)</a>:</h4>
<p><span class="user-mention silent" data-user-id="360405">Cameron Steffen</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/local.20crate.20only.20queries.3F/near/238305448">said</a>:</p>
<blockquote>
<p>Also, I wonder if we could have <code>tcx.local().query()</code> instead of <code>tcx.query(())</code></p>
</blockquote>
<p>We could even have <code>tcx.query()</code> in this case, but I am not sure this is worth it.</p>



<a name="238306378"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/local%20crate%20only%20queries%3F/near/238306378" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cameron Steffen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/local.20crate.20only.20queries.3F.html#238306378">(May 11 2021 at 13:26)</a>:</h4>
<p>Gotcha. In that case the unit makes sense.</p>



<a name="238306593"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/local%20crate%20only%20queries%3F/near/238306593" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cameron Steffen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/local.20crate.20only.20queries.3F.html#238306593">(May 11 2021 at 13:27)</a>:</h4>
<blockquote>
<p>We could even have <code>tcx.query()</code> in this case, but I am not sure this is worth it.</p>
</blockquote>
<p>That's a lot of work?</p>



<a name="238306899"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/local%20crate%20only%20queries%3F/near/238306899" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/local.20crate.20only.20queries.3F.html#238306899">(May 11 2021 at 13:29)</a>:</h4>
<p>Mostly adding an edge case in the rustc_middle::ty::query::define_callbacks macro. However, I think the macro is complicated enough as it is.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>